// times.js

export function countDownFun(time,type) {
	//当前时间戳
	let timestamp = new Date().getTime()
	let times = time*1000
	let playTime,
		day = 0,
		hour = 0,
		minute = 0,
		second = 0; //时间默认值
	if (times > 0) {
		second = Math.floor(times / 1000); //未来时间距离现在的秒数
		day = Math.floor(second / 86400); //整数部分代表的是天；一天有24*60*60=86400秒 ；
		second = second % 86400; //余数代表剩下的秒数；
		hour = Math.floor(second / 3600); //整数部分代表小时；
		second %= 3600; //余数代表 剩下的秒数；
		minute = Math.floor(second / 60);
		second %= 60;
	}

	
	if(type==2){
		let str
		if (day > 0) {
			if(second>0){
				str = `${day}天${hour}时${minute}分${second}秒`;
			}else if(minute>0){
				str = `${day}天${hour}时${minute}分`;
			}else if(hour>0){
				str = `${day}天${hour}时`;
			}else{
				str = `${day}天`;
			}
		}
		if (day <= 0 && hour > 0) {
			
			if(second>0){
				str = `${hour}小时${minute}分${second}秒`;
			}else if(minute>0){
				str = `${hour}小时${minute}分`;
			}else if(hour>0){
				str = `${hour}小时`;
			}
		}
		if (day <= 0 && hour <= 0) {
			
			if(second>0&&minute>0){
				str = `${minute}分${second}秒`;
			}else if(minute>0&&second==0){
				str = `${minute}分`;
			}else if(second>0){
				str = `${second}秒`;
			}
			
			
		}
		return str
	}else{
		//不足两位时添加0
		if (day <= 9) day = '0' + day;
		if (hour <= 9) hour = '0' + hour;
		if (minute <= 9) minute = '0' + minute;
		if (second <= 9) second = '0' + second;
		
		if (day > 0) {
			playTime = `${day}天${hour}:${minute}:${second}`;
		}
		if (day <= 0 && hour > 0) {
			playTime = `${hour}:${minute}:${second}`;
		}
		if (day <= 0 && hour <= 0) {
			playTime = `${minute}:${second}`;
		}
		return playTime
	}
	
	
}

